package com.sky.happygos.common.YiChart;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.sky.happygos.R;
import com.sky.happygos.utils.DensityUtil;

/**
 * Created by qqqqqqq on 2017/4/23.
 */

public class LineView extends View {

    Paint mPaint;
    int preValue = 0;
    int curValue = -1;
    int nextValue = 0;

    public LineView(Context context) {
        super(context);
        init();
    }

    public LineView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public LineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public void init(){

    }

    public void setData(int preValue,int curalue,int nextValue){
        this.preValue = preValue;
        this.curValue = curalue;
        this.nextValue = nextValue;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(curValue != -1) {
            mPaint = new Paint();
            mPaint.setColor(0xFFF4F4F4);
            mPaint.setAntiAlias(true);
            mPaint.setStrokeWidth(4);
            if (preValue == -1) {
                canvas.drawLine(DensityUtil.dip2px(getContext(), 20), curValue, DensityUtil.dip2px(getContext(), 40), (nextValue + curValue) / 2, mPaint);
            } else {

                if (nextValue == -1) {
                    canvas.drawLine(0, (preValue + curValue) / 2, DensityUtil.dip2px(getContext(), 20), curValue, mPaint);
                } else {
                    canvas.drawLine(0, (preValue + curValue) / 2, DensityUtil.dip2px(getContext(), 20), curValue, mPaint);
                    canvas.drawLine(DensityUtil.dip2px(getContext(), 20), curValue, DensityUtil.dip2px(getContext(), 40), (nextValue + curValue) / 2, mPaint);
                }
            }

            canvas.drawCircle(DensityUtil.dip2px(getContext(), 20), curValue, 15, mPaint);

        }

    }
}
